package com.hnhs.controller;

import com.hnhs.dto.ResponseDTO;
import com.hnhs.exception.BizException;
import com.hnhs.model.Category;
import com.hnhs.model.CategoryQuery;
import com.hnhs.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin // 后台解决跨域的问题
@RequestMapping("/api/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     *  code=1
     *  msg="成功"
     *  data=[{}]
     *  统一返回值
     */
   // @GetMapping("/api/category")
    @GetMapping
    public List<Category> select(CategoryQuery query){
        List<Category> select = categoryService.select(query);

//        if(1==1){
//            throw new BizException(88,"报错了 拜拜了您呢");
//        }
        return  select;
    }
    @PostMapping
   public Integer insert(@RequestBody Category category){
        return categoryService.insert(category);
   }

    @PutMapping
    public Integer update(@RequestBody Category category){
        return categoryService.update(category);
    }
    @DeleteMapping
    public Integer delete(Integer id){
        return categoryService.updateStatus(id);
    }
}
